package test7;

import java.util.LinkedList;
import java.util.List;

public class Demo5 {

    static LinkedList<Integer> track = new LinkedList<>();
    static List<List<Integer>> res = new LinkedList<>();
    static boolean[] flag;

    public static void main(String[] args) {
        int[] nums = {2, 3, 4, 5, 1, 0};
        flag = new boolean[nums.length];
        traverse(nums);
        System.out.println(res);
    }

    static void traverse(int[] nums) {
        if (nums.length == track.size()) {
            res.add(new LinkedList<>(track));
            return;
        }

        for (int i = 0; i < nums.length; i++) {

            if (flag[i]) continue;

            track.addLast(nums[i]);
            flag[i] = true;
            traverse(nums);
            track.removeLast();
            flag[i] = false;
        }
    }

}
